home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Online / Apache / include / php / ext / standard / php_smart_str.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-14  |  2.8 KB  |  89 lines

  1. /*
  2.    +----------------------------------------------------------------------+
  3.    | PHP version 4.0                                                      |
  4.    +----------------------------------------------------------------------+
  5.    | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group                   |
  6.    +----------------------------------------------------------------------+
  7.    | This source file is subject to version 2.02 of the PHP license,      |
  8.    | that is bundled with this package in the file LICENSE, and is        |
  9.    | available at through the world-wide-web at                           |
  10.    | http://www.php.net/license/2_02.txt.                                 |
  11.    | If you did not receive a copy of the PHP license and are unable to   |
  12.    | obtain it through the world-wide-web, please send a note to          |
  13.    | license@php.net so we can mail you a copy immediately.               |
  14.    +----------------------------------------------------------------------+
  15.    | Authors: Sascha Schumann <sascha@schumann.cx>                        |
  16.    +----------------------------------------------------------------------+
  17.  */
  18.  
  19. #ifndef PHP_SMART_STR_H
  20. #define PHP_SMART_STR_H
  21.  
  22. #include "php_smart_str_public.h"
  23.  
  24. #define smart_str_0(x) ((x)->c[(x)->len] = '\0')
  25.  
  26. #define smart_str_alloc(d,n,what) {\
  27.     if (!d->c) d->len = d->a = 0; \
  28.     newlen = d->len + n; \
  29.     if (newlen >= d->a) {\
  30.         d->c = perealloc(d->c, newlen + 129, what); \
  31.         d->a = newlen + 128; \
  32.     }\
  33. }
  34.  
  35. #define smart_str_appends_ex(dest, src, what) smart_str_appendl_ex(dest, src, strlen(src), what)
  36. #define smart_str_appends(dest, src) smart_str_appendl(dest, src, strlen(src))
  37.  
  38. #define smart_str_appendc(dest, c) smart_str_appendc_ex(dest, c, 0)
  39. #define smart_str_free(s) smart_str_free_ex(s, 0)
  40. #define smart_str_appendl(dest,src,len) smart_str_appendl_ex(dest,src,len,0)
  41. #define smart_str_append(dest, src) smart_str_append_ex(dest,src,0)
  42.  
  43. static inline void smart_str_appendc_ex(smart_str *dest, char c, int what)
  44. {
  45.     size_t newlen;
  46.  
  47.     smart_str_alloc(dest, 1, what);
  48.     dest->len = newlen;
  49.     dest->c[dest->len - 1] = c;
  50. }
  51.  
  52.  
  53. static inline void smart_str_free_ex(smart_str *s, int what)
  54. {
  55.     if (s->c) {
  56.         pefree(s->c, what);
  57.         s->c = NULL;
  58.     }
  59.     s->a = s->len = 0;
  60. }
  61.  
  62. static inline void smart_str_appendl_ex(smart_str *dest, const char *src, size_t len, int what)
  63. {
  64.     size_t newlen;
  65.  
  66.     smart_str_alloc(dest, len, what);
  67.     memcpy(dest->c + dest->len, src, len);
  68.     dest->len = newlen;
  69. }
  70.  
  71. static inline void smart_str_append_ex(smart_str *dest, smart_str *src, int what)
  72. {
  73.     smart_str_appendl_ex(dest, src->c, src->len, what);
  74. }
  75.  
  76. static inline void smart_str_setl(smart_str *dest, const char *src, size_t len)
  77. {
  78.     dest->len = len;
  79.     dest->a = len + 1;
  80.     dest->c = (char *) src;
  81. }
  82.  
  83. static inline void smart_str_sets(smart_str *dest, const char *src)
  84. {
  85.     smart_str_setl(dest, src, strlen(src));
  86. }
  87.  
  88. #endif
  89.